﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Abs.Core.Management;
using NUnit.Framework;

namespace Abs.Core.UnitTesting
{
    [TestFixture]
    public class AppointmentManagement
    {
        private Management.AppointmentManagement Management { get; set; }
        private int AppointmentId { get; set; }
        private string UserEmail { get; set; }
        private int RoomId { get; set; }
        private DateTime Now { get; set; }
        private string StartTime { get; set; }
        private string EndTime { get; set; }
        private string Comment { get; set; }
        
        [TestFixtureSetUp]
        public void BeforeAllTests()
        {
            this.Management = Manage.Appointment;
            this.AppointmentId = 11;
            this.UserEmail = "porter.scavo@abs.com";
            this.RoomId = 3;
            this.Now = DateTime.Now;
            this.StartTime = this.Now.ToString("M/d/yyyy h:mm tt");
            this.EndTime = this.Now.AddHours(3).ToString("M/d/yyyy h:mm tt");
            this.Comment = "Hello";
        }//end of public void BeforeAllTests()

        [Test]
        public void ManagementNotNull()
        {
            Assert.IsNotNull(this.Management);
        }//end of public void ManagementNotNull()

        //[Test]
        public void AddAppointment()
        {
            var isSuccess = this.Management.CreateAppointment(this.RoomId,
                                                              this.UserEmail,
                                                              this.StartTime,
                                                              this.EndTime,
                                                              this.Comment);
            Assert.True(isSuccess);
        }//end of public void CreateAppointment()

        //[Test]
        public void EditAppointment()
        {
            this.Comment = "Hello World";
            var isSuccess = this.Management.UpdateAppointment(this.AppointmentId,
                                                              this.RoomId, 
                                                              this.UserEmail, 
                                                              this.StartTime, 
                                                              this.EndTime,
                                                              this.Comment);
            Assert.True(isSuccess);
        }//end of public void EditAppointment()

        //[Test]
        public void ReadAppointment()
        {
            var appointment = this.Management.SelectAppointment(this.AppointmentId);
            Assert.AreEqual(this.Comment, appointment.Comment);
        }//end of public void SelectAppointment()

        //[Test]
        public void ReadAllAppointments()
        {
            var appointments = this.Management.SelectAllAppointments();
            var totalAppointments = appointments.Count;
            var expectedTotalAppointments = 3;
            Assert.AreEqual(expectedTotalAppointments, totalAppointments);
        }//end of public void SelectAllAppointments()

        //[Test]
        public void RemoveAppointment()
        {
            var isSuccess = this.Management.DeleteAppointment(this.AppointmentId);
            Assert.True(isSuccess);
        }//end of public void RemoveAppointment()

        //[Test]
        public void GetAppointmentsOnDate()
        {
            var appointments = this.Management.GetAppointmentsOnDate(this.StartTime);
            var totalAppointments = appointments.Count;
            var expectedTotalAppointments = 1;
            Assert.AreEqual(expectedTotalAppointments, totalAppointments);
        }//end of public void GetAppointmentsOnDate()

        //[Test]
        public void GetAvailableRooms()
        {
            var availableRooms = this.Management.GetAvailableRoomsOnDate("2012-01-02");
            var isAvailable = availableRooms[1].IsAvailableAtTime[8];
            Assert.False(isAvailable);
        }//end of public void GetAvailableRooms()
    }//end of public class AppointmentManagement
}//end of namespace ABS.UnitTesting